/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // 数据库链接配置
  config.mysql = {
    // database configuration
    client: {
      // host
      host: '127.0.0.1',
      // port
      port: '3306',
      // username
      user: 'root',
      // password
      password: 'root',
      // database
      database: 'myblogdb',
    },
    // load into app, default is open
    app: true,
    // load into agent, default is close
    agent: false,
  };

  config.security = {
    csrf: {
      enable: false
    },
    domainWhiteList: ['*']
    // domainWhiteList: ['http://127.0.0.1:8000', 'http://127.0.0.1:3000']

  };
  config.cors = {
    // origin: '*',
    // origin: [],
    // origin: ['http://127.0.0.1:8000'], //只允许这个域进行访问接口  (注意点：跨域访问cookies/session获取undefined是由于用了localhost，应该用ip或者域名的方式访问 ，credentials必须是true)
    credentials: true,   // 开启认证,允许Cookie/session可以跨域
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS'
  };
  config.origin = {
    whiteList: ['http://127.0.0.1:8000', 'http://127.0.0.1:3000']
  }

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1615628243150_3059';

  config.session = {
    key: 'SESSION_ID',
    maxAge: 1 * 600 * 1000,  //（10分钟） 过期时间 [hours * min * ms]
    httpOnly: true,
    encrypt: true,
    renew: false //延长会话有效期 
  }

  // add your middleware config here
  config.middleware = [];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  return {
    ...config,
    ...userConfig,
  };
};
